﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;

namespace FlashCards.WebApp.Models.Accounts
{
    [AttributeUsage(AttributeTargets.Property, AllowMultiple=true, Inherited = false)]
    public class AccountValidator : ValidationAttribute
    {
        //public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        //{
        //    return null;
        //}

        public override bool IsValid(object value)
        {
            var date = value as DateTime?;
            if (date.HasValue)
            {

            }

            return false;
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var date = value as DateTime?;
            if (date.HasValue)
            {
                if (date > new DateTime(1940, 1, 1))
                {
                    return ValidationResult.Success;
                }
            }

            return new ValidationResult("Should be date between 1940 and current date");
        }
    }
}